/**
 * jgamebox
 *
 * outlook@China software studio
 * Copyright (c) 2008-2011. All Rights Reserved.
 * http://www.outlook.com
 */

package org.outlook.jgamebox.role.fighter;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.outlook.common.log.LogUtil;
import org.outlook.comon.ai.AIer;
import org.outlook.jgamebox.api.Robot;
import org.outlook.jgamebox.map.Scene;

/**
 * function:
 * @author watson  email: watson.wu@hotmail.com
 * @date 2011-5-30
 */
public abstract class AIFighter extends Fighter implements Robot {

	private static final long serialVersionUID = 1L;
	private static final Log logger = LogFactory.getLog(AIFighter.class);
	
	private int AILevel;

	@Override
	protected void action() {
		LogUtil.debug(logger, "========", this);
		if(shouldMove())
			move();
		if(Scene.isBeyondMap(this) && AIer.get50Percents() || shouldChangeDirection())
			redirect();
		if(shouldFire())
			fire();
	}

	private boolean shouldFire() {
		return AIer.isHit(getAILevel());
	}

	@Override
	public int getAILevel() {
		return AILevel;
	}

	@Override
	public void setAILevel(int aiLevel) {
		this.AILevel = aiLevel;
	}

	@Override
	public abstract void fire();

}
